import cmd,os

class WindowsShell(cmd.Cmd):
    intro = 'Welcome to the turtle shell.   Type help or ? to list commands.\n'
    prompt = '(CmdTools-HongDaYu) '
    file = None

    def __init__(self):
        cmd.Cmd.__init__(self) #继承父类的初始化方法,使用命令行操作windows
        self.file = open("test.log",'w')

    def close(self):
        if self.file:
            self.file.close()
            self.file = None
    
    def do_exit(self,arg):
        "exit cmd tools"
        exit()

    def do_sys(self,arg):
        "windows system command "
        #windows 的系统命令
        os.system(arg)

    def parse(arg):
        'Convert a series of zero or more numbers to an argument tuple'
        return tuple(map(int, arg.split()))

    def precmd(self, line):
        line = line.lower()
        if self.file and 'playback' not in line:
            print(line, file=self.file)
        return line
        
if __name__ == '__main__':
    WindowsShell().cmdloop()